package com.xiaotu.service.train.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import com.xiaotu.dao.train.SwTrainMapper;
import com.xiaotu.model.SwTrainModel;
import com.xiaotu.service.train.SwTrainService;
import com.xiaotu.vo.SwTrainVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author zhangxiao
 * @create 2021-08-20 15:12
 */
@Service
@Transactional
public class SwTrainServiceImpl implements SwTrainService<SwTrainModel, SwTrainVo> {

    @Autowired
    private SwTrainMapper swTrainMapper;

    @Override
    public void update(SwTrainModel swTrainModel) {
        Validator.validateTrue(ObjectUtil.isNotNull(swTrainModel.getTrainId()), "trainId 不能为空");
        swTrainMapper.updateByPrimaryKey(swTrainModel);
    }

    @Override
    public SwTrainVo selectOne(Integer primaryKey) {
        SwTrainModel m = swTrainMapper.selectByPrimaryKey(primaryKey);
        SwTrainVo v = new SwTrainVo();
        BeanUtil.copyProperties(m, v);
        return v;
    }

    @Override
    public List<SwTrainModel> selectList() {
        return swTrainMapper.selectAll();
    }

}
